import { createStore } from "vuex";
import MAIN_STORE from '@/store/store.js'
import Api from "@/api";
const Store = createStore({
  state: {
    cesiumSceneIsCreated: false,
    // 时间轴数据
    dataOfYear: [],
    // 底图的默认 ID
    baseMapActiveId: 'base-tianditu',
    // originView: [116.76518883912635, 36.18327910283026]
    originView: [120.3862161399353, 36.07547667197184]
  },
  getters: {
  },
  mutations: {
    SET_CESIUM_SCENE_CREATED(state) {
      state.cesiumSceneIsCreated = true;
    },
    SET_BASE_MAP_ACTIVE_ID(state, { id }) {
      state.baseMapActiveId = id;
    },
    LOCATION_CERTAIN_VIEW(state, { position, accu, zoom }) {
      const mapIns = MAIN_STORE.GLOBAL_MAP_INS
      if (!mapIns) { return }
      const obj = {
        center: ol.proj.fromLonLat(position)
      }
      if(zoom) {
        obj.zoom = zoom
      } else if (accu) {
        obj.zoom = mapIns.getView().getMaxZoom()
      }
      mapIns.getView().animate(obj)
    },
    LOCATION_ORIGIN_VIEW(state) {
      const mapIns = MAIN_STORE.GLOBAL_MAP_INS
      if (!mapIns) { return }
      mapIns.getView().animate({
        zoom: 12,
        center: ol.proj.fromLonLat(state.originView)
      })
    }
  },
});
export default Store;
